package com.rd.student.jiaji.class2.duyukun.Day0727;

import java.io.*;

public class TestStream {

    public static void main(String[] args) throws Exception {
        testRead1();
    }

    public static void testRead() throws Exception {
        InputStream is = new FileInputStream("stream.txt");

        while (true){
            int len = is.read();
            if (len == -1) break;

            byte[] arr = new byte[1];
            arr[0] = (byte) len;
            System.out.println(new String(arr));
        }
        is.close();
    }

    public static void testRead1() throws Exception {
        File file = new File("stream.txt");
        InputStream is = new FileInputStream("stream.txt");
        is.read();

        int cnt = 0;
        while (true) {
            byte[] arr = new byte[28];
            int len = is.read(arr);
            if (len == -1) {
                System.out.println();
                System.out.println(cnt);
                System.out.println("读取完成");
                break;
            }
            String content = new String(arr);
            System.out.println(len + "--" + content);
            cnt++;
        }
        is.close();
    }
}
